﻿(function() {
    var scriptName = "ExtendedInfoPopup";

    function execute() {

        Type.registerNamespace('ATDW.IFL.Controls.InfoPopup');

        ATDW.IFL.Controls.InfoPopup.InfoPopupBehavior = function(element) {
            ATDW.IFL.Controls.InfoPopup.InfoPopupBehavior.initializeBase(this, [element]);

        }
        ATDW.IFL.Controls.InfoPopup.InfoPopupBehavior.prototype = {
            initialize: function() {
                /// <summary>
                /// Initialize the behavior
                /// </summary>
                ATDW.IFL.Controls.InfoPopup.InfoPopupBehavior.callBaseMethod(this, 'initialize');

                var e = this.get_element();
                var context = this;
                var f = Function.createDelegate(this, this._build);
                $('input,textarea,button,select', e).focus(function() {
                    f();
                    $('.fix', e).css('position', 'relative');
                    $('.inlay', e).css('visibility', 'visible').show();
                });

                $('input,textarea,button,select', e).blur(function() {
                    $('.inlay', e).hide();
                    $('.fix', e).css('position', 'static');
                });

                //this._app_onload$delegate = Function.createDelegate(this, this._app_onload);
                //Sys.Application.add_load(this._app_onload$delegate);

                //this._build();
            },
            dispose: function() {
                /// <summary>
                /// Initialize the behavior
                /// </summary>
                ATDW.IFL.Controls.InfoPopup.InfoPopupBehavior.callBaseMethod(this, 'dispose');
            },
            _app_onload: function() {

                Sys.Application.remove_load(this._app_onload$delegate);
                this._build();
            },
            _build: function() {
                var e = this.get_element();
                var wrapper = $('#fieldWrapper', e)[0];

                var leftBoxTop = $('#leftBoxTop', e)[0];
                var leftBoxBottom = $('#leftBoxBottom', e)[0];
                var rightBoxTop = $('#rightBoxTop', e)[0];
                var rightBoxBottom = $('#rightBoxBottom', e)[0];
                var rightBoxInner = $('#rightBoxInner', e)[0];

                var leftWidth = $(wrapper).outerWidth();
                var leftHeight = $(wrapper).outerHeight();
                $(leftBoxTop).width(leftWidth);
                $(leftBoxTop).height(leftHeight);
                $(leftBoxBottom).css('top', leftHeight);
                $(leftBoxBottom).width(leftWidth);

                $(rightBoxTop).css('left', $(wrapper).outerWidth() + 3 + 'px');
                $(rightBoxTop).height($(wrapper).height());
                $(rightBoxBottom).css('left', $(wrapper).outerWidth() + 2 + 'px');
                $(rightBoxBottom).css('top', $(wrapper).outerHeight() + 3 + 'px');
                $(rightBoxInner).css('left', $(wrapper).outerWidth() + 2 + 'px');
                var rightHeight = rightBoxInner.scrollHeight;

                $(rightBoxBottom).height(rightHeight - $(wrapper).outerHeight());
                $(rightBoxInner).height(rightHeight);
                $('#shadowLeft', e).height(leftHeight).width(leftWidth);
                $('#shadowRight', e).height(rightHeight).css('left', $(wrapper).outerWidth() + 2 + 'px');
            }
        }
        ATDW.IFL.Controls.InfoPopup.InfoPopupBehavior.registerClass('ATDW.IFL.Controls.InfoPopup.InfoPopupBehavior', Sys.Extended.UI.BehaviorBase);
        Sys.registerComponent(ATDW.IFL.Controls.InfoPopup.InfoPopupBehavior, { name: "infoPopup" });

    } // execute

    if (window.Sys && Sys.loader) {
        Sys.loader.registerScript(scriptName, ["ExtendedBase", "ExtendedCommon"], execute);
    }
    else {
        execute();
    }

})();